package day5.Exer;

import java.util.*;

public class HashMapexer {
    public static void main(String[] args) {
        Map<String, String> hm = new HashMap<>();
        hm.put("书", "book");
        hm.put("玻璃", "glass");
        hm.put("书包", "bag");
        hm.put("钢笔", "pen");
        hm.put("纸", "paper");
        hm.put("眼睛", "glass");
        System.out.println("请输入要查找的中文");
        Scanner in = new Scanner(System.in);
        String key = in.next();
        if (hm.containsKey(key)) {
            Set<String> st = hm.keySet();
            Iterator<String> ir = st.iterator();
            while (ir.hasNext()) {
                String next = ir.next();
                if ((hm.get(next)).equals(hm.get(key))) {
                    System.out.println(key + "对应的英文是" + hm.get(next));
                }
            }
        } else {
            System.out.println(key + "对应的英文没找到");
        }

        System.out.println("请输入要查找的英文");
        String value = in.next();
        if (!hm.containsValue(value)) {
            System.out.println(value + "对应的中文没找到");
            return;
        }
        Iterator<String> ir = hm.keySet().iterator();
        while (ir.hasNext()) {
            String next = ir.next();
            if (hm.get(next).equals(value)) {
                System.out.println(value + "对应的中文是" + next);
            }
        }
    }
}
